<?php

/**
 * SfGuardUser form.
 *
 * @package    virtualdelivery
 * @subpackage form
 * @author     Your name here
 */
class SfGuardUserForm extends sfGuardUserAdminForm {

    public function configure() {
        parent::configure();

        unset(
                $this['last_login'],
                $this['created_at'],
                $this['salt'],
                $this['algorithm'],
                $this['is_super_admin']
        );

        $this->widgetSchema->setLabels(array(
            'username' => 'Usuario',
            'password' => 'Contraseña',
            'password_again' => 'Contraseña (nuevamente)',
            'is_active' => 'Activo',
            'sf_guard_user_group_list' => 'Grupos',
            'sf_guard_user_permission_list' => 'Permisos',
        ));
    }

    public function setup() {
        parent::setup();

        $this->setWidgets(array(
            'id' => new sfWidgetFormInputHidden(),
            'username' => new sfWidgetFormInput(),
            'algorithm' => new sfWidgetFormInput(),
            'salt' => new sfWidgetFormInput(),
            'password' => new sfWidgetFormInput(),
            'created_at' => new sfWidgetFormDateTime(),
            'last_login' => new sfWidgetFormDateTime(),
            'is_active' => new sfWidgetFormInputCheckbox(),
            'is_super_admin' => new sfWidgetFormInput(),
            'sf_guard_user_group_list' => new sfWidgetFormPropelChoiceMany(array('model' => 'SfGuardGroup')),
            'sf_guard_user_permission_list' => new sfWidgetFormPropelChoiceMany(array('model' => 'SfGuardPermission')),
            'usr_surname' => new sfWidgetFormInput(),
            'usr_name' => new sfWidgetFormInput(),
            'usr_phone' => new sfWidgetFormInput(),
            'usr_movil' => new sfWidgetFormInput(),
            'usr_ids_id' => new sfWidgetFormPropelChoice(array('model' => 'PersonalIds', 'add_empty' => true)),
            'usr_ids_nro' => new sfWidgetFormInput(),
            'usr_state' => new sfWidgetFormPropelChoice(array('model' => 'GeoStates', 'add_empty' => false)),
            'usr_city' => new sfWidgetFormPropelChoice(array('model' => 'GeoCities', 'add_empty' => false)),
            'usr_address' => new sfWidgetFormInput(),
            'usr_address_nro' => new sfWidgetFormInput(),
            'usr_address_floor' => new sfWidgetFormInput(),
            'usr_address_dpt' => new sfWidgetFormInput(),
            'usr_email' => new sfWidgetFormInput(),
            'usr_birthday_date' => new sfWidgetFormDateTime(),
        ));

        $this->setValidators(array(
            'id' => new sfValidatorPropelChoice(array('model' => 'SfGuardUser', 'column' => 'id', 'required' => false)),
            'username' => new sfValidatorString(array('max_length' => 128)),
            'algorithm' => new sfValidatorString(array('max_length' => 128)),
            'salt' => new sfValidatorString(array('max_length' => 128)),
            'password' => new sfValidatorString(array('max_length' => 128)),
            'created_at' => new sfValidatorDateTime(array('required' => false)),
            'last_login' => new sfValidatorDateTime(array('required' => false)),
            'is_active' => new sfValidatorBoolean(),
            'is_super_admin' => new sfValidatorInteger(),
            'sf_guard_user_group_list' => new sfValidatorPropelChoiceMany(array('model' => 'SfGuardGroup', 'required' => false)),
            'sf_guard_user_permission_list' => new sfValidatorPropelChoiceMany(array('model' => 'SfGuardPermission', 'required' => false)),
            'usr_surname' => new sfValidatorString(array('max_length' => 50)),
            'usr_name' => new sfValidatorString(array('max_length' => 50)),
            'usr_phone' => new sfValidatorString(array('max_length' => 15, 'required' => false)),
            'usr_movil' => new sfValidatorString(array('max_length' => 15, 'required' => false)),
            'usr_ids_id' => new sfValidatorPropelChoice(array('model' => 'PersonalIds', 'column' => 'ids_id', 'required' => false)),
            'usr_ids_nro' => new sfValidatorInteger(array('required' => false)),
            'usr_state' => new sfValidatorPropelChoice(array('model' => 'GeoStates', 'column' => 'sta_id')),
            'usr_city' => new sfValidatorPropelChoice(array('model' => 'GeoCities', 'column' => 'cty_id')),
            'usr_address' => new sfValidatorString(array('max_length' => 50)),
            'usr_address_nro' => new sfValidatorString(array('max_length' => 10)),
            'usr_address_floor' => new sfValidatorInteger(array('required' => false)),
            'usr_address_dpt' => new sfValidatorString(array('max_length' => 2, 'required' => false)),
            'usr_email' => new sfValidatorString(array('max_length' => 40, 'required' => false)),
            'usr_birthday_date' => new sfValidatorDateTime(array('required' => false)),
        ));

        $this->validatorSchema->setPostValidator(
                new sfValidatorPropelUnique(array('model' => 'SfGuardUser', 'column' => array('username')))
        );

        $this->widgetSchema->setNameFormat('sf_guard_user[%s]');

        $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
    }

}
